package com.woniuxy.yoga.notice.service.impl;

import com.woniuxy.yoga.notice.dao.model.SystemNotice;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class Test {
    public static void main(String[] args) {
        ArrayList<SystemNotice> systemNotices = new ArrayList<>();
        SystemNotice systemNotice = new SystemNotice();
        systemNotice.setSystemNoticeId(1);
        systemNotice.setPublishDate("2023-12-10 08:30:00");
        systemNotices.add(systemNotice);
        List<String> timeStrings = new ArrayList<>();//("2023-12-10T08:30:00", "2023-12-09T12:00:00", "2023-12-11T06:45:00");
        timeStrings.add("2023-12-10 08:30:00");
        timeStrings.add("2023-12-09 12:00:00");
        timeStrings.add("2023-12-11 06:45:00");
        String earliestTime = timeStrings.stream()
                .map(s -> LocalDateTime.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
                .min(LocalDateTime::compareTo)
                .map(LocalDateTime::toString)
                .orElse(null);
        String latestTime = timeStrings.stream()
                .map(s -> LocalDateTime.parse(s, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
                .max(LocalDateTime::compareTo)
                .map(LocalDateTime::toString)
                .orElse(null);
        SystemNotice max = systemNotices.stream()
                .max(Comparator.comparing(o ->
                        LocalDateTime.parse(o.getPublishDate(),
                                DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))))
                .orElse(null);
        System.out.println(max.getPublishDate());

        List<String> numbers = Arrays.asList("1", "2", "3", "4", "5", "6");
        systemNotices.get(0).setPublishDate("5");
        SystemNotice systemNotice1 = new SystemNotice();
        systemNotice1.setSystemNoticeId(2);
        systemNotice1.setPublishDate("7");
        systemNotices.add(systemNotice1);
        Optional<Integer> maxNumber = systemNotices.stream().map(o->o.getPublishDate())
                .map(Integer::valueOf) // 将字符串转换为整数
                .max(Comparator.comparingInt(Integer::intValue)); // 找出最大值
        if (maxNumber.isPresent()) {
            int maxNum = maxNumber.get();
            System.out.println("Max number is " + maxNum);
        } else {
            System.out.println("No max number found");
        }
    }
}
